﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccessLayer;
using MyCommon;

namespace BussinessLayer
{
    public class ThietBiBaoHanhBO : BaseBO
    {
        #region Singleton implemented
        private static ThietBiBaoHanhBO _instance;
        private ThietBiBaoHanhBO()
        { }
        public static ThietBiBaoHanhBO getInstance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new ThietBiBaoHanhBO();
                }
                return _instance;
            }
        }
        #endregion

        public IEnumerable<ThietBiBaoHanh> GetAllThietBiBaoHanh()
        {
            return _dao.ThietBiBaoHanh.GetAllThietBiBaoHanh();
        }

        public IEnumerable<ThietBiBaoHanh> GetAllThietBiBaoHanhOrderByTen()
        {
            return _dao.ThietBiBaoHanh.GetAllThietBiBaoHanhOrderByTen();
        }
        public ThietBiBaoHanh GetThietBiBaoHanhById(int id)
        {
            return _dao.ThietBiBaoHanh.GetThietBiBaoHanhById(id);
        }
        public bool UpdateThietBiBaoHanh(ThietBiBaoHanh inThietBiBaoHanh)
        {
            return _dao.ThietBiBaoHanh.UpdateThietBiBaoHanh(inThietBiBaoHanh);
        }
        public bool InsertThietBiBaoHanh(ThietBiBaoHanh inThietBiBaoHanh)
        {
            return _dao.ThietBiBaoHanh.InsertThietBiBaoHanh(inThietBiBaoHanh);
        }
        public ReturnValue<bool> DelThietBiBaoHanh(int id)
        {
            return _dao.ThietBiBaoHanh.DelThietBiBaoHanh(id);
        }
        public string GenerateMaThietBiBaoHanh()
        {
            ThietBiBaoHanh aObj = _dao.ThietBiBaoHanh.GetLastRecord();
            if (aObj != null)
            {
                return Utils.GenerateCode(CodeType.ThietBiBaoHanh, aObj.Id + 1);
            }
            else
            {
                return Utils.GenerateCode(CodeType.ThietBiBaoHanh, 1);
            }

        }
        public ThietBiBaoHanh GetLastRecord()
        {
            return _dao.ThietBiBaoHanh.GetLastRecord();
        }
    }
}
